package com.csd.action.document;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.csd.helper.ActionResult;
import com.csd.pojo.DocumentRecord;
import com.csd.pojo.Project;
import com.csd.serviceImpl.DocumentRecordService;
import com.csd.serviceImpl.ProjectService;

/**
 * 
 * Action:列出工程所有文档
 * 
 * @author csd
 * @version 1.0
 * 
 * <br>
 *          修订时间：2009-12-17 <br>
 *          修改原因：创建文件 <br>
 *          修改人：刘世彬 <br>
 * 
 */
public class DocumentListAction {

	/** <文档提交阶段，文档> */
	private Map<String, DocumentRecord> stat;

	/** 开发周期 */
	private String cycle;

	private DocumentRecordService service;

	private ProjectService projectService;

	/** 工程当前状态 */
	private String projectState;

	public String getProjectState() {
		return projectState;
	}

	public void setProjectState(String projectState) {
		this.projectState = projectState;
	}

	public String getCycle() {
		return cycle;
	}

	public void setCycle(String cycle) {
		this.cycle = cycle;
	}

	public ProjectService getProjectService() {
		return projectService;
	}

	public void setProjectService(ProjectService projectService) {
		this.projectService = projectService;
	}

	public DocumentRecordService getService() {
		return service;
	}

	public void setService(DocumentRecordService service) {
		this.service = service;
	}

	public Map<String, DocumentRecord> getStat() {
		return stat;
	}

	public void setStat(Map<String, DocumentRecord> stat) {
		this.stat = stat;
	}

	public String execute() {
		String result = ActionResult.fail;

		// 查询团队的工程
		List list = projectService.listTeamProject();
		if (list != null && list.size() > 0) {
			Project project = (Project) list.get(0);
			this.cycle = project.getCycle();
			this.projectState = project.getState();
			// 查询工程的所有文档
			List<DocumentRecord> temp = service.listDocumentByProject(project.getId());

			// 将文档按照文档的状态，放入map
			if (temp != null) {
				stat = new HashMap<String, DocumentRecord>();
				if (temp.size() > 0) {
					for (DocumentRecord record : temp) {
						stat.put(record.getStage(), record);
					}
				}
				result = ActionResult.success;
			}

		}

		return result;
	}
}
